<template>
	<view class="one">
		<view class="nav">
			<!-- 评价项目板块 -->
			<view class="section-container" v-for="(item, index) in evaluations" :key="index">
				<view class="evaluation-item">
					<view class="header">
						<view class="user-info">
							<text class="user-name">{{item.userName}}</text>
							<view class="detail-btn" @click="viewDetail(item)">查看详情</view>
						</view>
						<view class="divider"></view>
					</view>
					<view class="order-info">
						<view class="order-number">
							<text class="label">订单编号: </text>
							<text class="number">{{item.orderNumber}}</text>
						</view>
						<view class="rating">
							<text>综合评分：{{item.rating}}分</text>
							<uni-rate 
								:value="item.rating" 
								:readonly="!item.isEditing"
								:size="16"
								:allow-half="true"
								active-color="#FFB800"
								:margin="4"
								@change="(value) => handleRating(value, index)"
								@mouseenter="showRatingTip"
							/>
							<text v-if="item.isEditing" class="rating-tip">{{ratingTip}}</text>
						</view>
						<text class="eval-time">评价时间：{{item.time}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ratingTip: '',
				evaluations: [
					{
						userName: '张女士',
						orderNumber: '202101083123',
						rating: 3,
						time: '2023-03-12 11:02',
						isEditing: false
					},
					{
						userName: '张女士',
						orderNumber: '202101083123',
						rating: 3,
						time: '2023-03-12 11:02',
						isEditing: false
					}
				]
			}
		},
		methods: {
			handleRating(value, index) {
				// 更新评分
				this.evaluations[index].rating = value;
				// 这里可以调用接口保存评分
				this.saveRating(this.evaluations[index]);
			},
			showRatingTip(e) {
				// 根据星级显示提示文字
				const tips = ['很差', '差', '一般', '好', '很好'];
				const value = Math.ceil(e.value);
				this.ratingTip = tips[value - 1] || '';
			},
			viewDetail(item) {
				// 切换编辑状态
				item.isEditing = !item.isEditing;
			},
			saveRating(evaluation) {
				// 这里添加保存评分的接口调用
				console.log('保存评分:', evaluation);
				uni.showToast({
					title: '评分已更新',
					icon: 'success'
				});
			}
		}
	}
</script>

<style>
page{
	background:#F7F7F7;
	}  
	.one{
		padding-top: 20rpx;
		height: 200rpx;
		background-color: #2D80F9;
	}
	.nav{
		width: 680rpx;
		min-height: 80vh;
		margin: 0 auto;
		padding: 20rpx;
		background-color: transparent;
	}
	.section-container {
		background-color: #FFFFFF;
		border-radius: 20rpx;
		padding: 30rpx 20rpx;
		margin-bottom: 20rpx;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
	}
	.evaluation-item {
		padding: 0 10rpx;
	}
	.header {
		margin-bottom: 20rpx;
	}
	.user-info {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 10rpx 20rpx;
	}
	.divider {
		height: 2rpx;
		background-color: #EEEEEE;
		margin: 0 10rpx;
	}
	.user-name {
		font-size: 32rpx;
		color: #333;
		font-weight: 500;
	}
	.detail-btn {
		padding: 10rpx 30rpx;
		background-color: #2D80F9;
		color: #FFFFFF;
		font-size: 28rpx;
		border-radius: 30rpx;
		cursor: pointer;
	}
	.detail-btn:active {
		opacity: 0.8;
	}
	.order-info {
		padding-top: 20rpx;
		font-size: 28rpx;
		color: #666;
	}
	.order-number {
		display: flex;
		align-items: center;
		margin-bottom: 15rpx;
	}
	.order-number .label,
	.order-number .number {
		font-size: 28rpx;
		margin-right: 20rpx;
		color: #2D80F9;  /* 标签和数字都使用浅蓝色 */
	}
	.rating {
		display: flex;
		align-items: center;
		margin-bottom: 15rpx;
		position: relative;
	}
	.rating text {
		margin-right: 20rpx;
	}
	.eval-time {
		display: block;
		color: #999;
	}
	.rating-tip {
		position: absolute;
		left: 100%;
		top: 50%;
		transform: translateY(-50%);
		font-size: 24rpx;
		color: #FFB800;
		margin-left: 10rpx;
		white-space: nowrap;
	}
	.stars {
		display: none;
	}
</style>
